package com.ss.android.common.applog;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;

import com.bytedance.common.utility.collection.WeakHandler;

final class ANRMonitor implements WeakHandler.Callback {
    v a;
    Handler b;
    volatile boolean c;
    boolean d;
    final Object e;
    int f;
    volatile int g;
    long h;
    long i;
    long j;
    private long k;
    private static ANRMonitor l;

    private ANRMonitor(v arg3) {

        this.c = true;
        this.d = true;
        this.e = new Object();
        this.f = 0;
        this.b = new WeakHandler(Looper.getMainLooper(), ((WeakHandler.Callback) this));
        this.a = arg3;
        new b(this, "ANRMonitor-Thread").start();
    }

    public final void a() {
        this.c = true;
        if (this.d) {
            this.d = false;
            Object v1 = this.e;
            synchronized (v1) {
                this.e.notify();
            }
        }

        if (this.k <= 0) {
            this.k = System.currentTimeMillis();
        }
    }

    public static ANRMonitor a(v arg2) {
        ANRMonitor v0_1;
        Class v1 = ANRMonitor.class;
        synchronized (v1) {
            if (l == null) {
                l = new ANRMonitor(arg2);
            }

            v0_1 = l;
        }
        return v0_1;
    }

    static String b() {
        StackTraceElement[] v1 = Looper.getMainLooper().getThread().getStackTrace();
        StringBuilder v2 = new StringBuilder();
        int v3 = v1.length;
        int v0;
        for (v0 = 0; v0 < v3; ++v0) {
            v2.append(v1[v0].getClassName()).append(".").append(v1[v0].getMethodName()).append("(").append(v1[v0].getFileName()).append(":").append(v1[v0].getLineNumber()).append(")\n");
        }

        return v2.toString();
    }

    public final void handleMsg(Message message) {
        long v0 = System.currentTimeMillis();
        if (message != null && message.what == 1) {
            this.g = message.arg1;
            this.h = v0;
        }

        if ((this.k <= 0 || v0 - this.k > 60000) && !AppLog.n()) {
            this.c = false;
            this.d = true;
        }
    }
}

